#include <cppunit/config/SourcePrefix.h>
#include "Follow.h"
#include "TestFollow.h"

#include <iostream>
#include <string>


void FollowTest::setUp()
{
	cout << "Test PKB Follows setUp()\n";
}
void FollowTest::tearDown()
{}
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( FollowTest ); 
// method to test the constructor
void FollowTest::testConstructor() { 
// create a Follow object
// check that the object is constructed correctly
	Follow myFollowTable = Follow::Follow();
}
void FollowTest::testSetFollowsAndGetFollowsAndGetFollowedBy(){
	Follow myFollowTable = Follow::Follow();

	myFollowTable.setFollows(1,2);
	myFollowTable.setFollows(2,3);
	
	CPPUNIT_ASSERT_EQUAL(2, myFollowTable.getFollows(1));
	CPPUNIT_ASSERT_EQUAL(3, myFollowTable.getFollows(2));
	CPPUNIT_ASSERT_EQUAL(-1, myFollowTable.getFollows(4));
	CPPUNIT_ASSERT_EQUAL(-1, myFollowTable.getFollows(3));


	CPPUNIT_ASSERT_EQUAL(1, myFollowTable.getFollowedBy(2));
	CPPUNIT_ASSERT_EQUAL(2, myFollowTable.getFollowedBy(3));
	CPPUNIT_ASSERT_EQUAL(-1, myFollowTable.getFollowedBy(4));
	CPPUNIT_ASSERT_EQUAL(-1, myFollowTable.getFollowedBy(1));
	
}
void FollowTest::testIsFollows(){
	Follow myFollowTable = Follow::Follow();
	myFollowTable.setFollows(1,2);
	myFollowTable.setFollows(2,3);
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isFollows(1,2));
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isFollows(2,3));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(3,4));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(2,1));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(3,1));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(1,4));
}
/*********************************
    ety c1 c2 c3 c4
 ety 0  0  0  0  0
 p1  0  0  1  0  0
 p2  0  0  0  1  0
 p3  0  0  0  0  1
 p4  0  0  0  0  0

 follows(1,2)
 follows(2,3)
 follows(2,4)
**********************************/
void FollowTest::testSetFollowsBitMap(){
	Follow myFollowTable = Follow::Follow();
	myFollowTable.setFollows(1,2);
	myFollowTable.setFollows(2,3);
	myFollowTable.setFollows(3,4);
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isBitMapSet());
	vector<vector<bool>> sampleBitMap;
	for (int i = 0 ; i < 5; i++){
		vector<bool> temp;
		temp.clear();
		if (i==0 || i==4 ){
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
		}else if(i==1){
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(true);
			temp.push_back(false);
			temp.push_back(false);
		}else if(i==2){
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(true);
			temp.push_back(false);
		}else{
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(true);
		}
		sampleBitMap.push_back(temp);
	}
	myFollowTable.setFollowsBitMap(sampleBitMap);
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isBitMapSet());
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isFollows(1,2));
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isFollows(2,3));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(2,4));
	CPPUNIT_ASSERT_EQUAL(false, myFollowTable.isFollows(2,1));
	CPPUNIT_ASSERT_EQUAL(true, myFollowTable.isFollows(3,4));
}